package com.wn.main.ui.category.repository

import com.wn.common.model.CategoryItem
import com.wn.network.api.ApiInterface
import com.wn.network.repository.BaseRepository
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2025/2/11 16:34
 * @Description: 分类页仓库
 */
@ViewModelScoped
class CategoryRepository @Inject constructor(private val api: ApiInterface) : BaseRepository() {
  /**
   * 获取分类信息
   * @param scope CoroutineScope
   * @param errorCall Function2<Int?, String?, Unit>?
   * @param showLoading Function1<Boolean, Unit>?
   * @return StateFlow<MutableList<CategoryItem>?>
   */
  fun getCategoryData(
    scope: CoroutineScope,
    errorCall: ((Int?, String?) -> Unit)? = null,
    showLoading: ((Boolean) -> Unit)? = null,
  ): StateFlow<MutableList<CategoryItem>?> = callStateFlow(scope, errorCall, showLoading) {
    api.getCategoryData()
  }
}